# https://leetcode.cn/problems/lemonade-change/
from typing import List
class Solution:
    def lemonadeChange(self, bills: List[int]) -> bool:
        f_number = 0 # 5块的数量
        t_number = 0 # 10块的数量
        for i in bills:
            if i == 5:
                f_number += 1 # 5块不需要找0
            elif i == 10:
                if f_number > 0:
                    f_number -= 1 # 有 5块的就减1
                    t_number += 1 # 10块的加1
                else:
                    return False # 没有5块的返回False
            elif i == 20:
                if t_number >0 and f_number > 0:
                    # 优先使用10块的
                    t_number -= 1
                    f_number -= 1
                # 没有10块的使用3张5块的
                elif f_number >= 3:
                    f_number -= 3
                # 没有三张5块的，返回False
                else:
                    return False
        return True
bills = [5,5,5,20]
sl = Solution()
print(sl.lemonadeChange(bills))
